import http from '@/utils/http'

const BASE_URL = '/system/file'

/** 系统文件类型 */
export interface FileItem {
  id: string
  name: string
  fileSize: number
  fileUrl: string
  thumbnailSize: number
  thumbnailUrl: string
  extension: string
  fileType: string
  storageId: string
  storageName: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
}

/** 文件资源统计信息 */
export interface FileStatisticsResp {
  type: string
  size: any
  number: number
  unit: string
  data: Array<FileStatisticsResp>
}

export interface FileQuery extends SortQuery {
  name?: string
  fileType?: string
  storageId?: string
}

export interface FilePageQuery extends FileQuery, PageQuery {

}

/** @desc 查询文件列表 */
export function getPage(query: FilePageQuery) {
  return http.get<Page<FileItem[]>>(`${BASE_URL}/page`, query)
}

/** @desc 查询文件资源统计统计 */
export function getFileStatistics() {
  return http.get<FileStatisticsResp>(`${BASE_URL}/statistics`)
}

/** @desc 创建文件 */
export function upload(data: any) {
  return http.post(`${BASE_URL}/upload`, data)
}

/** @desc 修改文件 */
export function update(data: any, id: string) {
  return http.post(`${BASE_URL}/update/${id}`, data)
}

/** @desc 删除文件 */
export function remove(ids: string | Array<string>) {
  return http.post(`${BASE_URL}/delete/${ids}`)
}
